import libvirt;
from virt import Guest
import time
import virt

def handler(vs, got, fi):
    fi.write(got);
    return len(got);
    pass

if __name__ == "__main__":
    
    conn = libvirt.open("qemu:///system");
    
    if(conn is None):
        print "error";
    else:
        
#        capxml = conn.getCapabilities();
#        print capxml;
#        
#        caps = virt.CapabilitiesParse.Parse(capxml);
#        
#        uuid = virt.util.uuidToString(virt.util.randomUUID());
#        mac = virt.util.randomMAC(type='qemu');
#        
#        guest = Guest.Guest("kvm", "testw", uuid, "1048576", "1", False, "/home/kelly/iso/win711.img", "/home/kelly/iso/win7.iso", mac, "5905", "0.0.0.0", caps);
#                            
#        xml = guest.get_xml_config();
#        
#        #print xml;
#        
# #        dom = conn.createXML(xml, 0);
#        
#        dom = conn.defineXML(xml);
#        
#        dom.create();
        
#        print conn.listDefinedInterfaces();
#        i = conn.interfaceLookupByName('vnet0');
#        print i.XMLDesc(0);
        virtd = conn.lookupByName('test11');
        print virtd.XMLDesc(8);
        print virtd.vcpus();
        print virtd.info();
#        nd = conn.nodeDeviceLookupByName('net_vnet0_fe_54_00_3f_25_0b');
#        print nd.parent();
#        print virtd.interfaceStats("lo");
#        print virtd.vcpus();
#        print virtd.vcpuPinInfo(0);
#        print virtd.state(0);
#        print virtd.memoryStats();
#        
#        while(True):
#            m = virtd.memoryStats();
#            print (m['actual'] / 1024), "M", m['rss'] / 1024, "M";
#            time.sleep(1);
#            
        
#        while(True):
#            
#            l1 = virtd.vcpus()[0][0][2];
#            print l1;
#            time.sleep(1);
#            l2 = virtd.vcpus()[0][0][2];
#            
#            tl = (l2 - l1) / 1000 / 1000000.0;
#            
#            
#            
#            print tl ;
#            
#            pass